package com.baoer.service.impl;

import com.baoer.R;
import com.baoer.entity.Ordersmall;
import com.baoer.mapper.OrdersmallMapper;
import com.baoer.service.OrdersmallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class OrdersmallImpl implements OrdersmallService {

    @Autowired
    private OrdersmallMapper ordersmallMapper;
    //所有的订单
    @Override
    public R ordersmallList(Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        double pageCount = ordersmallMapper.ordersmallCount();
        pageCount = (int) Math.ceil(pageCount / pageSize);
        pageIndex = (pageIndex - 1) * pageSize;
        map.put("pageIndex", pageIndex);
        List<Ordersmall> ordersmallList = ordersmallMapper.ordersmallList(map);
        Map<String, Object> res = new HashMap<>();
        res.put("ordersmallList", ordersmallList);
        res.put("pageCount", pageCount);
        return R.ok(res);
    }
    //处理中的订单
    @Override
    public R ordersmallListDealing(Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        double pageCount = ordersmallMapper.ordersmallListDealingCount();
        pageCount = (int) Math.ceil(pageCount / pageSize);
        pageIndex = (pageIndex - 1) * pageSize;
        map.put("pageIndex", pageIndex);
        List<Ordersmall> ordersmallListDealing = ordersmallMapper.ordersmallListDealing(map);
        Map<String, Object> res = new HashMap<>();
        res.put("ordersmallListDealing", ordersmallListDealing);
        res.put("pageCount", pageCount);
        return R.ok(res);
    }
    //已确定的订单
    @Override
    public R ordersmallListDeal(Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        double pageCount = ordersmallMapper.ordersmallListDealCount();
        pageCount = (int) Math.ceil(pageCount / pageSize);
        pageIndex = (pageIndex - 1) * pageSize;
        map.put("pageIndex", pageIndex);
        List<Ordersmall> ordersmallListDeal = ordersmallMapper.ordersmallListDeal(map);
        Map<String, Object> res = new HashMap<>();
        res.put("ordersmallListDeal", ordersmallListDeal);
        res.put("pageCount", pageCount);
        return R.ok(res);
    }
    //拒绝的订单
    @Override
    public R ordersmallListDealfail(Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        double pageCount = ordersmallMapper.ordersmallListDealfailCount();
        pageCount = (int) Math.ceil(pageCount / pageSize);
        pageIndex = (pageIndex - 1) * pageSize;
        map.put("pageIndex", pageIndex);
        List<Ordersmall> ordersmallListDealfail = ordersmallMapper.ordersmallListDealfail(map);
        Map<String, Object> res = new HashMap<>();
        res.put("ordersmallListDealfail", ordersmallListDealfail);
        res.put("pageCount", pageCount);
        return R.ok(res);
    }
    //订单详情
    //产品信息
    @Override
    public R ordersmallListInfoProduct(int id) {
        return R.ok(ordersmallMapper.ordersmallListInfoProduct(id));
    }
    //订单信息
    @Override
    public R ordersmallListInfoOrder(int id) {
        return R.ok(ordersmallMapper.ordersmallListInfoOrder(id));
    }
    //供应商单位
    @Override
    public R ordersmallListStore(int id) {
        return R.ok(ordersmallMapper.ordersmallListStore(id));
    }

    @Override
    public R ordersmallListSearch(Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        double pageCount = ordersmallMapper.ordersmallListSearchCount(map);
        pageCount = (int) Math.ceil(pageCount / pageSize);
        pageIndex = (pageIndex - 1) * pageSize;
        map.put("pageIndex", pageIndex);
        List<Ordersmall> ordersmallListSearch = ordersmallMapper.ordersmallListSearch(map);
        Map<String, Object> res = new HashMap<>();
        res.put("ordersmallListSearch", ordersmallListSearch);
        res.put("pageCount", pageCount);
        return R.ok(res);
    }



}
